package cn.edu.xmu.orderpayment.payment.model.bo;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

@Data
@NoArgsConstructor
public class Refund {
    private Long id;
    private String tradeSn;
    private Long patternId;
    private Long paymentId;
    private Long amount;
    private String documentId;
    private Byte documentType;
    private LocalDateTime refundTime;
    private Byte state;
    private String descr;
    private Long adjustId;
    private String adjustName;
    private LocalDateTime adjustTime;
    private Long creatorId;
    private String creatorName;
    private Long modifierId;
    private String modifierName;
    private LocalDateTime gmtCreate;
    private LocalDateTime gmtModified;

    public State getState() {
        return State.getStateByCode(Integer.valueOf(state));
    }
    public void setState(State state) {
        this.state=state.getCode().byteValue();
    }

    public DocumentType getDocumentType() {
        return DocumentType.getDocumentTypeByCode(Integer.valueOf(documentType));
    }
    public void setDocumentType(DocumentType documentType) {
        this.documentType=documentType.getCode().byteValue();
    }

    public enum DocumentType{
        NORMAL(0,"订单"),
        BOND(1,"保证金"),
        AFTERSALE(2,"售后");
        private static final Map<Integer, DocumentType> DOCUMENT_TYPE_MAP;
        static {
            DOCUMENT_TYPE_MAP = new HashMap();
            for (DocumentType enum1 : values()) {
                DOCUMENT_TYPE_MAP.put(enum1.code, enum1);
            }
        }
        private int code;
        private String description;
        DocumentType(int code, String description) {
            this.code = code;
            this.description = description;
        }
        public static DocumentType getDocumentTypeByCode(Integer code) {
            return DOCUMENT_TYPE_MAP.get(code);
        }
        public Integer getCode() {
            return code;
        }
        public String getDescription() {
            return description;
        }
    }

    public enum State {
        WAIT_REFUND(0, "待退款"),
        HAS_REFUND(1, "已退款"),
        HAS_RECONCILED(2, "已对账"),
        HAS_LIQUIDATED(3, "已清算"),
        FAILED_REFUND(4,"退款失败"),
        CANCELED(5,"取消");
        private static final Map<Integer, State> STATE_MAP;
        static {
            STATE_MAP = new HashMap();
            for (State enum1 : values()) {
                STATE_MAP.put(enum1.code, enum1);
            }
        }
        private int code;
        private String description;
        State(int code, String description) {
            this.code = code;
            this.description = description;
        }
        public static State getStateByCode(Integer code) {
            return STATE_MAP.get(code);
        }
        public Integer getCode() {
            return code;
        }
        public String getDescription() {
            return description;
        }
    }
}
